﻿using HRMSystem;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.Linq;

namespace HRMSystem.DBServices
{
    public class ContactService : GenericService<Contact>
    {

        public static List<Contact> GetContactListByEmployeeID(int employeeId) 
        {
            try
            {
                return db.Contacts.Where(c => c.EMPLOYEE_ID.Equals(employeeId)).ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        internal static int InsertContacts(List<Contact> contacts)
        {
            try
            {
                foreach(Contact c in contacts)
                    db.Contacts.Add(c);

                return db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return 0;
            }
        }
    }
}
